package jdbc1;

import java.sql.*;

/**
 * @author oldliu
 * @since 1.0
 */
public class TestConnection {
    public static void main(String[] args) throws InterruptedException {
        try {
            //static{}执行了
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }
        //ip信息，端口，库名，其他参数
        //jdbc:mysql://localhost:3308/java83
        String url="jdbc:mysql://localhost:3308/java83?useUnicode=true&characterEncoding=utf8&useSSL=false&serverTimezone=Asia/Shanghai";
        Connection connections[]=new Connection[300];
        for (int i = 0; i < connections.length; i++) {
            try {
                connections[i] = DriverManager.getConnection(url, "xukang", "Xu1234");
                System.out.println("获得了第"+(i+1)+"个连接");
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }
        Thread.sleep(100000);
        for (int i = 0; i < connections.length; i++) {
            try {
                connections[i].close();
            } catch (SQLException e) {
                e.printStackTrace();
            }
        }


    }
}
